package com.ross.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author RossZhang
 */
@Controller
public class UserController {
    @RequestMapping(value = "/loginA.do")
    public String userLogin(String username, String password){
        System.out.println("用户输入的用户名："+username+"密码："+password);
        //1、先得到当前的用户
        Subject currentUser = SecurityUtils.getSubject();
        System.out.println("Subject得到的用户："+currentUser);

        //2、【判断是否登录
        if (!currentUser.isAuthenticated()){

            //封装用户名和密码
            UsernamePasswordToken token = new UsernamePasswordToken(username, password);

            //设置记住我
            //token.setRememberMe(true);

            try {
                currentUser.login(token);
            }
            /*catch (UnknownAccountException uae){
                System.out.println("用户不存在！"+token.getPrincipal());
                return "login";
            }catch (IncorrectCredentialsException ice){
                System.out.println("用户名或密码不存在！");
                return "login";
            }catch (LockedAccountException lae){
                System.out.println("账户被锁定！");
                return "login";
            }*/
            catch (AuthenticationException ae){
                System.out.println("认证失败！");
                return "login";
            }
        }
        return "index2";
    }

    @RequestMapping(value = "/add.do")
    public String register(){
        System.out.println("注册用户！");
        return "register";
    }
    @RequestMapping(value = "/delete.do")
    public String delete(){
        System.out.println("删除用户！");
        return "test";
    }
    @RequestMapping(value = "/select.do")
    public String select(){
        System.out.println("查询用户！");
        return "order_list";
    }
    @RequestMapping(value = "/update.do")
    public String update(){
        System.out.println("更新用户！");
        return "order_update";
    }


}
